package ic

import (
	"bytes"
	"fmt"
	"image"

	"golang.org/x/image/bmp"
)

type BMPConverter struct{}

func (b *BMPConverter) SupportedFormat() string {
	return "BMP"
}

func (b *BMPConverter) FileExtension() string {
	return ".bmp"
}

func (b *BMPConverter) MimeType() string {
	return "image/bmp"
}

func (b *BMPConverter) Encode(img image.Image, options ...Options) ([]byte, error) {
	var buf bytes.Buffer

	if err := bmp.Encode(&buf, img); err != nil {
		return nil, fmt.Errorf("BMP编码失败: %v", err)
	}

	return buf.Bytes(), nil
}

func (b *BMPConverter) Decode(data []byte) (image.Image, error) {
	return bmp.Decode(bytes.NewReader(data))
}
